class ProductModel {
    constructor(){
        this.data = [
            {year:1990, data:[{city:"上海",level1:543,level2:510},{city:"北京",level1:541,level2:431}]},
            {year:1991, data:[{city:"上海",level1:558,level2:423},{city:"北京",level1:556,level2:432}]},
            {year:1992, data:[{city:"上海",level1:523,level2:444},{city:"北京",level1:552,level2:421}]},
            {year:1993, data:[{city:"上海",level1:501,level2:456},{city:"北京",level1:533,level2:456}]},
            {year:1994, data:[{city:"上海",level1:523,level2:487},{city:"北京",level1:522,level2:467}]},
            {year:1995, data:[{city:"上海",level1:589,level2:478},{city:"北京",level1:578,level2:478}]},
            {year:1996, data:[{city:"上海",level1:590,level2:488},{city:"北京",level1:600,level2:444}]},
            {year:1997, data:[{city:"上海",level1:510,level2:410},{city:"北京",level1:567,level2:433}]},
            {year:1998, data:[{city:"上海",level1:529,level2:423},{city:"北京",level1:583,level2:422}]},
            {year:1999, data:[{city:"上海",level1:538,level2:467},{city:"北京",level1:528,level2:500}]},
            {year:2000, data:[{city:"上海",level1:588,level2:460},{city:"北京",level1:576,level2:498}]},
            {year:2001, data:[{city:"上海",level1:576,level2:480},{city:"北京",level1:566,level2:488}]},
            {year:2002, data:[{city:"上海",level1:548,level2:423},{city:"北京",level1:538,level2:444}]},
            {year:2003, data:[{city:"上海",level1:600,level2:500},{city:"北京",level1:599,level2:456}]},
            {year:2004, data:[{city:"上海",level1:611,level2:502},{city:"北京",level1:601,level2:498}]},
            {year:2005, data:[{city:"上海",level1:534,level2:434},{city:"北京",level1:555,level2:467}]},
            {year:2006, data:[{city:"上海",level1:520,level2:423},{city:"北京",level1:534,level2:488}]},
            {year:2007, data:[{city:"上海",level1:515,level2:410},{city:"北京",level1:587,level2:498}]},
            {year:2008, data:[{city:"上海",level1:555,level2:444},{city:"北京",level1:567,level2:456}]},
            {year:2009, data:[{city:"上海",level1:587,level2:446},{city:"北京",level1:534,level2:477}]},
            {year:2010, data:[{city:"上海",level1:523,level2:448},{city:"北京",level1:555,level2:448}]},
            {year:2011, data:[{city:"上海",level1:601,level2:501},{city:"北京",level1:589,level2:467}]},
            {year:2012, data:[{city:"上海",level1:566,level2:498},{city:"北京",level1:588,level2:487}]},
            {year:2013, data:[{city:"上海",level1:589,level2:468},{city:"北京",level1:577,level2:498}]},
            {year:2014, data:[{city:"上海",level1:523,level2:479},{city:"北京",level1:566,level2:468}]},
            {year:2015, data:[{city:"上海",level1:513,level2:470},{city:"北京",level1:555,level2:440}]},
            {year:2016, data:[{city:"上海",level1:526,level2:432},{city:"北京",level1:523,level2:476}]},
            {year:2017, data:[{city:"上海",level1:578,level2:424},{city:"北京",level1:534,level2:488}]},
            {year:2018, data:[{city:"上海",level1:598,level2:455},{city:"北京",level1:546,level2:490}]},
            {year:2019, data:[{city:"上海",level1:588,level2:465},{city:"北京",level1:578,level2:450}]},
            {year:2020, data:[{city:"上海",level1:583,level2:475},{city:"北京",level1:567,level2:440}]},
            {year:2021, data:[{city:"上海",level1:585,level2:486},{city:"北京",level1:533,level2:440}]},
            {year:2022, data:[{city:"上海",level1:576,level2:488},{city:"北京",level1:544,level2:486}]},
            {year:2023, data:[{city:"上海",level1:545,level2:460},{city:"北京",level1:555,level2:467}]}
        ]
    }

    async findAll(){
        return this.data
    }

    async findByYear(year){
        return this.data.filter(item=> item.year === year);
    }

    async findPage(pageNum=1,pageSize=3){
        let total = this.data.length;
        let totalPage = Math.ceil(this.data.length/pageSize);

        let start = (pageNum-1)*pageSize;
        let data = this.data.slice(start, start+pageSize); // 一页的数据

        let prevPage = pageNum == 1 ? totalPage : pageNum-1;
        let nextPage = pageNum == totalPage ? 1 : pageNum+1;
        return {prevPage,pageNum,pageSize,nextPage,total,totalPage,data}
    }
}
module.exports =  ProductModel;